import time
import os
from selenium import webdriver
from selenium.webdriver.common.by import By

class Register:
    def __init__(self):
        # 打开浏览器
        self.driver = webdriver.Chrome()
        self.driver.maximize_window()
        # 打开本地链接
        self.url = 'file:///' + os.path.abspath('注册实例.html')
        self.driver.get(self.url)

    def register(self):
        # 输入用户名
        self.driver.find_element(By.ID, 'user').send_keys('123456')
        time.sleep(2)
        # 输入密码
        self.driver.find_element(By.ID, 'password').send_keys('123abc')
        time.sleep(2)
        # 输入电话号码
        self.driver.find_element(By.ID, 'tel').send_keys('13667167950')
        time.sleep(2)
        # 输入电子邮箱
        self.driver.find_element(By.ID, 'email').send_keys('849509226@qq.com')
        time.sleep(2)
        # 点击注册
        self.driver.find_element(By.XPATH, '//*[@id="zc"]/fieldset/button').click()

    def register1(self):
        # 切换至注册1
        frame1 = self.driver.find_element(By.ID, 'idframe1')
        self.driver.switch_to.frame(frame1)
        # 输入用户名
        time.sleep(2)
        self.driver.find_element(By.ID, 'userA').send_keys('123456')
        # 输入密码
        time.sleep(2)
        self.driver.find_element(By.ID, 'passwordA').send_keys('123abc')
        # 输入电话号码
        time.sleep(2)
        self.driver.find_element(By.ID, 'telA').send_keys('13667167950')
        # 输入电子邮箱
        self.driver.find_element(By.ID, 'emailA').send_keys('849509226@qq.com')
        # 点击注册
        time.sleep(2)
        self.driver.find_element(By.XPATH, '//*[@id="zc"]/fieldset/button').click()

    def register2(self):
        # 切换至注册2
        frame2 = self.driver.find_element(By.NAME, 'myframe2')
        self.driver.switch_to.frame(frame2)
        # 输入用户名
        time.sleep(2)
        self.driver.find_element(By.ID, 'userB').send_keys('123456')
        # 输入密码
        time.sleep(2)
        self.driver.find_element(By.ID, 'passwordB').send_keys('123abc')
        # 输入电话号码
        time.sleep(2)
        self.driver.find_element(By.ID, 'telB').send_keys('13667167950')
        # 输入电子邮箱
        self.driver.find_element(By.ID, 'emailB').send_keys('849509226@qq.com')
        # 点击注册
        time.sleep(2)
        self.driver.find_element(By.XPATH, '//*[@id="zc"]/fieldset/button').click()

    def quit(self):
        # 退出浏览器
        time.sleep(2)
        self.driver.quit()

if __name__ == '__main__':
    reg = Register()
    reg.register()
    reg.register1()
    reg.register2()
    reg.quit()

